package com.yan.utils;

import java.util.HashMap;
import java.util.Map;

public class EnumUtil {

    public enum ChatResult {
        BLOCKED_LIST(1010, "您已被禁言"),
        SUCCESS(0001, "发送成功"),
        WORD_LIMIT(1011, "发送失败，字数超过限制"),
        MSG_ID_NULL(1012, "msgId不能为空"),
        USER_VALIDATE_FAIL(1013, "用户登录校验失败"),
        REPORT_USER_NOT_EXIST(1014, "被举报用户不存在"),
        MSG_CODE_NULL(1015, "msgCode不能为空"),
        DESIGNATE_USER_NOT_EXIST(1016, "@用户不存在"),
        EXIST_MSG_ID(1018, "msgId已存在"),
        INTEGRATION_PLATFORM_CONNECTION_REFUSE(1017, "综合平台ice连接失败");


        private int resultCode;

        private String resultMsg;

        public int getResultCode() {
            return resultCode;
        }

        public void setResultCode(int resultCode) {
            this.resultCode = resultCode;
        }

        public String getResultMsg() {
            return resultMsg;
        }

        public void setResultMsg(String resultMsg) {
            this.resultMsg = resultMsg;
        }

        ChatResult(int resultCode, String resultMsg) {
            this.resultCode = resultCode;
            this.resultMsg = resultMsg;
        }

        private static ChatResult getChatResult(int resultCode) {

            for (ChatResult result : ChatResult.values()) {
                if (resultCode == result.getResultCode()) {
                    return result;
                }
            }
            return null;
        }
    }


    public enum ChatType {

        BASKETBALL("basketball"), FOOTBALL("football"), PUBLIC("public"), SNOOKER("snooker"), TENNIS(
                "tennis"), CHAT_USER_INFO("mobile:user:login:{0}");

        ChatType(String type) {
            this.type = type;
        }

        private String type;

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        private static final Map<String, ChatType> map = new HashMap<String, ChatType>();

        static {
            for (ChatType chatType : values()) {
                map.put(chatType.type, chatType);
            }
        }

        public static ChatType fromString(String type) {
            return map.get(type);
        }


    }

    public static void main(String args[]) {
        System.out.println(ChatResult.BLOCKED_LIST.resultCode + ChatResult.BLOCKED_LIST.resultMsg);
        System.out.println(ChatType.BASKETBALL.name() + " " + ChatType.BASKETBALL.getType() + " " + ChatType.fromString("basketball"));

        ChatResult result = ChatResult.getChatResult(1010);
        if (result != null) {
            System.out.println("==" + result.getResultCode() + " " + result.getResultMsg() + " " + result.name() + " ");
            
            result.setResultCode(404);
            result.setResultMsg("not found");
            System.out.println(";;;;;" + result.getResultCode() + " " + result.getResultMsg() + " " + result.name() + " ");
        }


        ChatResult chatResult = ChatResult.valueOf("SUCCESS");

        System.out.println("======" + chatResult.getResultCode());
//        switch (chatResult) {
//            case SUCCESS: {
//                System.out.println("SUCCESS========="+chatResult.resultMsg+"   "+chatResult.resultCode);
//                //自定义业务逻辑
//            }
//            ;
//            break;
//            case WORD_LIMIT: {
//                System.out.println("WORD_LIMIT");
//                //自定义业务逻辑
//            }
//            ;
//
//            break;
//
//
//            default:
//                System.out.println("defalut bankList=");
//                break;
//        }


    }
}
